﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Pb;

public class HistoryPanel : MonoBehaviour
{

    public GameObject grid;
    public GameObject cardsRecordPre;
    public List<PaiCard> cardRecordList;
    public GameObject closeBtn;

    void Start()
    {
        UIEventListener.Get(closeBtn).onClick = ButtonClick;
        LogMsg();
    }

    void ButtonClick(GameObject button)
    {
        if (button.name == "CloseBtn")
        {
            Destroy(gameObject);
        }
    }

    void LogMsg()
    {
        List<UISprite> tempCardsSpriteList = new List<UISprite>();
        for (int i = 0; i < cardRecordList.Count / 8; i++)
        {
            GameObject cardRecord = Instantiate(cardsRecordPre);
            cardRecord.transform.parent = grid.transform;
            cardRecord.transform.localScale = Vector3.one;
            cardRecord.transform.localPosition = Vector3.zero;
            HistoryItem historyItem = cardRecord.GetComponent<HistoryItem>();
            for (int j = 0; j < historyItem.cardSpriteList.Count; j++)
            {
                //historyItem.cardSpriteList[j].spriteName = cardRecordList[i].Id.ToString();
                tempCardsSpriteList.Add(historyItem.cardSpriteList[j]);
            }
        }

        for (int i = 0; i < cardRecordList.Count; i++)
        {
            tempCardsSpriteList[i].spriteName = cardRecordList[i].Id.ToString();
        }
    }

}
